import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import { terser } from "rollup-plugin-terser";
import cleanup from "rollup-plugin-cleanup";
// 保留头部信息
import hashbang from "rollup-plugin-hashbang";

export default [
  // {
  //   input: "./src/bin.ts",
  //   output: {
  //     dir: "dist",
  //     format: "cjs",
  //     entryFileNames: "[name].cjs.js",
  //   },
  //   external: ['inquirer'],
  //   plugins: [resolve(), commonjs(), typescript(), terser(), cleanup()],
  // },
  /** 打包命令行脚手架，可通过控制台通过yarn local-cli运行 */
  {
    input: "./src/bin.ts",
    output: {
      dir: "dist",
      format: "esm",
      entryFileNames: "[name].esm.mjs",
    },
    external: ['inquirer'],
    plugins: [resolve(), commonjs(), typescript(), terser(), cleanup(), (hashbang.default)()],
  },
  /**
   * 打包npm包，可以导出使用
   */
  {
    input: "./src/index.ts",
    output: {
      dir: "dist",
      format: "cjs",
      entryFileNames: "[name].cjs.js",
    },
    external: ['inquirer'],
    plugins: [resolve(), commonjs(), typescript(), terser(), cleanup()],
  },
  {
    input: "./src/index.ts",
    output: {
      dir: "dist",
      format: "esm",
      entryFileNames: "[name].esm.js",
    },
    external: ['inquirer'],
    plugins: [resolve(), commonjs(), typescript(), terser(), cleanup()],
  },
];
